package com.example.easyscript.common.core.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    /**
     * 请求结果对象
     **/
    private T result;

    /**
     * 请求结果的状态码
     **/
    private int retcode;

    /**
     * 错误消息
     **/
    private String msg;

    /**
     * 错误详细
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String detail;

    /**
     * 请求id
     **/
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String traceId;

    public static <T> ResponseResult<T> success(T data) {
        return ResponseResult.<T>builder()
                .retcode(1)
                .msg("成功")
                .result(data)
                .build();
    }

    public static ResponseResult success() {
        return success(null);
    }
}
